home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Interactive Web Graphics with Shout 3D
/
Interactive Web Graphics With Shout 3D.iso
/
mac
/
Code
/
Chapter Code.exe
/
Chapter09
/
FlexibleSpeedPanel.java
< prev
next >
Wrap
Text File
|
2000-09-09
|
2KB
|
84 lines
package applets;
import shout3d.*;
import shout3d.core.*;
import shout3d.math.*;
public class FlexibleSpeedPanel extends Shout3DPanel implements DeviceObserver {
float speed = 0.0f; //percentage per second
TimeSensor timer;
double timeLength;
BezierVecInterpolator interp;
float fraction = 0;
//screen pixels
int pixelStartY;
int pixelEndY;
public FlexibleSpeedPanel (Shout3DApplet applet){
super(applet);
}
public void customInitialize() {
getRenderer().addRenderObserver(this, null);
addDeviceObserver(this,"MouseInput", null);
timer =(TimeSensor) getNodeByName("world-TIMER");
timeLength = timer.cycleInterval.getValue();
//use this to set speed factor
interp =(BezierVecInterpolator) getNodeByName("Cone01-BEZPOS-INTERP");
}
protected void finalize() {
getRenderer().removeRenderObserver(this);
removeDeviceObserver(this,"MouseInput");
}
public boolean onDeviceInput(DeviceInput di, Object userData) {
MouseInput mi = (MouseInput) di;
switch (mi.which){
case MouseInput.DOWN:
pixelStartY = mi.y;
return true;
case MouseInput.UP:
speed = 0.0f;
return true;
case MouseInput.DRAG:
int pixelEndY = mi.y;
int dragDistanceY = pixelEndY - pixelStartY;
//convert drag to speed
//at 70 pixels per meter/second
speed = 33.33f/dragDistanceY;
return true;
}//end of switch
return false;
}
public void onPreRender (Renderer r, Object o) {
float fractionDelta = speed/getFramesPerSecond();
fraction = fraction + fractionDelta;
interp.fraction.setValue(fraction);
interp.update();
}
} //end of class